﻿using AutoMapper;
using Domain.Flow;
using MediatR;
using U.B.ErrorCode;
using U.B.Repistory;
using U.B.WriteApi.Command.RabbitBWss;

namespace U.B.WriteApi.CommandHander.RabbitBWDD
{
    public class AddSupplierCommandHander : IRequestHandler<AddSupplierCommand, ApiResult<object>>
    {
        public readonly IRepistory<Supplier> _supplierRepository;
        public readonly IMapper _mapper;

        public AddSupplierCommandHander(IRepistory<Supplier> supplierRepository, IMapper mapper)
        {
            _supplierRepository = supplierRepository;
            _mapper = mapper;
        }
        /// <summary>
        /// 添加供应商
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        public Task<ApiResult<object>> Handle(AddSupplierCommand request, CancellationToken cancellationToken)
        {
            ApiResult<object> result = new ApiResult<object>();
            var supplier = _mapper.Map<Supplier>(request);
            _supplierRepository.Add(supplier);
            result.Data = supplier;
            result.Message=Renum.添加成功.ToString();
            result.code = Renum.添加成功 ;
            return Task.FromResult(result);
        }
    }
}
